package c.e.b.h.e.s.j;

import c.e.b.h.e.b;
import c.e.b.h.e.k.a;
import c.e.b.h.e.k.q0;
import c.e.b.h.e.n.d;
import c.e.b.h.e.s.i.g;
import com.huawei.agconnect.exception.AGCServerException;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;

/* compiled from: DefaultSettingsSpiCall */
public class c extends a implements d {
    public b f;

    public c(String str, String str2, c.e.b.h.e.n.c cVar) {
        c.e.b.h.e.n.a aVar = c.e.b.h.e.n.a.GET;
        b bVar = b.a;
        super(str, str2, cVar, aVar);
        this.f = bVar;
    }

    public final c.e.b.h.e.n.b d(c.e.b.h.e.n.b bVar, g gVar) {
        e(bVar, "X-CRASHLYTICS-GOOGLE-APP-ID", gVar.a);
        e(bVar, "X-CRASHLYTICS-API-CLIENT-TYPE", "android");
        e(bVar, "X-CRASHLYTICS-API-CLIENT-VERSION", "17.2.2");
        e(bVar, "Accept", "application/json");
        e(bVar, "X-CRASHLYTICS-DEVICE-MODEL", gVar.b);
        e(bVar, "X-CRASHLYTICS-OS-BUILD-VERSION", gVar.c);
        e(bVar, "X-CRASHLYTICS-OS-DISPLAY-VERSION", gVar.d);
        e(bVar, "X-CRASHLYTICS-INSTALLATION-ID", ((q0) gVar.e).b());
        return bVar;
    }

    public final void e(c.e.b.h.e.n.b bVar, String str, String str2) {
        if (str2 != null) {
            bVar.d.put(str, str2);
        }
    }

    public final Map<String, String> f(g gVar) {
        HashMap hashMap = new HashMap();
        hashMap.put("build_version", gVar.h);
        hashMap.put("display_version", gVar.g);
        hashMap.put("source", Integer.toString(gVar.i));
        String str = gVar.f;
        if (!c.e.b.h.e.k.g.r(str)) {
            hashMap.put("instance", str);
        }
        return hashMap;
    }

    public JSONObject g(d dVar) {
        int i = dVar.a;
        b bVar = this.f;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("Settings result was: ");
        stringBuilder.append(i);
        bVar.b(stringBuilder.toString());
        Object obj = (i == AGCServerException.OK || i == 201 || i == 202 || i == 203) ? 1 : null;
        if (obj != null) {
            String str = dVar.b;
            try {
                return new JSONObject(str);
            } catch (Exception e) {
                b bVar2 = this.f;
                StringBuilder g = c.b.a.a.a.g("Failed to parse settings JSON from ");
                g.append(this.a);
                bVar2.c(g.toString(), e);
                c.b.a.a.a.u("Settings response ", str, this.f);
                return null;
            }
        }
        b bVar3 = this.f;
        StringBuilder g2 = c.b.a.a.a.g("Failed to retrieve settings from ");
        g2.append(this.a);
        bVar3.d(g2.toString());
        return null;
    }
}
